﻿#ifndef SERIALPORTWRAP_H
#define SERIALPORTWRAP_H
#include <QObject>
#include <QSerialPort>
#pragma execution_character_set("utf-8")
#include "baserequester.h"

class SerialPortWrap : public BaseRequester
{
    Q_OBJECT
public:
    static QStringList getParityList();

    static QMap<QString,QSerialPort::Parity> getParityMap();

    static QStringList getDataList();

    static QMap<QString,QSerialPort::DataBits> getDataMap();

    static QStringList getStopList();

    static QMap<QString,QSerialPort::StopBits> getStopMap();

    static QStringList getFlowList();

    static QMap<QString, QSerialPort::FlowControl> getFlowMap();

    // BaseRequester interface
public:
    virtual bool request(QByteArray data, QByteArray &rec) override;
    virtual bool requestNoReply(QByteArray data) override;

public:
    explicit SerialPortWrap(QObject *parent = nullptr);

    void setSerialPort(QSerialPort *port);

signals:
    void receivedData(QByteArray data);

public slots:

private:
    QSerialPort *_serial=nullptr;
    QList<QByteArray> _recList;

    void waitMs(int ms);

private slots:
    void onError(QSerialPort::SerialPortError err);
    void onReadyReady();
};

#endif // SERIALPORTWRAP_H
